package br.com.appestoque.seguranca;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashCode {

	private static final String algoritmo = "MD5";
	private static final String codificador = "UTF8";
	
    public HashCode() {
    }

	public String processar(String input){
		try {
			MessageDigest md = MessageDigest.getInstance(algoritmo);			
			byte[] messageDigest;
            messageDigest = md.digest(input.getBytes(codificador));
			StringBuffer sb = new StringBuffer();
	        for (int i = 0; i < messageDigest.length; i++) {
	          sb.append(Integer.toString((messageDigest[i] & 0xff) + 0x100, 16).substring(1));
	        }
	        input = sb.toString();
		} catch (NoSuchAlgorithmException e1) {
			e1.printStackTrace();
		} catch (UnsupportedEncodingException e2) {
			e2.printStackTrace();
        }
		return input;
	}

}